//文件下载
export function exportFile(res, fileName, type) {
  //contentType 字典
  const dict = {
    zip: "application/zip",
    tar: 'application/x-tar',
    doc: 'application/msword',
    docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    xls: 'application/vnd.ms-excel',
    xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    ppt: 'application/vnd.ms-powerpoint',
    pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
    json: "application/json",
    csv: 'text/csv,charset=UTF-8',
    txt: 'text/plain',
  };

  const link = document.createElement('a');
  let blob = new Blob([res], {
    type: dict[type] || 'text/plain,charset=UTF-8'
  });
  if (!!window.ActiveXObject || "ActiveXObject" in window) {
    window.navigator.msSaveOrOpenBlob(blob, fileName);
  } else {
    let iconv = require('iconv-lite');
    iconv.skipDecodeWarning = true // 忽略警告
    link.style.display = 'none'
    link.href = URL.createObjectURL(blob)
    link.setAttribute('download', fileName)
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link);
  }

}
